class PositionsController < ApplicationController
	layout "positions"
	
	active_scaffold :position do |config|
                config.actions = [:create, :update, :list, :delete, :search]
                config.label = "Positions"
		config.columns[:name].label = "Position Title"
		config.columns[:ovposition].label = "OneWorld Position"
		config.list.label = "All Positions"
		config.list.columns = [:id,:name, :technology, :seniority, :team, :ovposition, :hc_approval_date, :priority_date, :hiring_type, :wave, :comments,:in_use] 
		config.create.columns = [:name, :technology, :seniority, :team, :ovposition, :hc_approval_date, :priority_date, :hiring_type, :wave, :comments] 
		config.update.columns = [:name, :technology, :seniority, :team, :ovposition, :hc_approval_date, :priority_date, :hiring_type, :wave, :comments] 
		config.create.label = "Add New Position"
		config.columns[:technology].form_ui = :select 
		config.columns[:team].form_ui = :select 
		config.columns[:ovposition].form_ui = :select 
		config.columns[:wave].form_ui = :select     
                config.columns[:name].set_link('index', :parameters => {:controller=> :history})    
                config.list.per_page = 5
		config.columns[:technology].search_sql = "technologies.name"
		config.columns[:team].search_sql = "teams.name"
		config.columns[:ovposition].search_sql = "ovpositions.name"
		config.columns[:wave].search_sql = "waves.name"
		config.search.columns << [:technology, :team, :ovposition, :wave, :comments]
	end 

	

        def conditions_for_collection
            if params[:is_in_use] == "Free"
              #For Open Positions embedded scaffold
              #['in_use = ?', "Free"]
              ['positions.id not in (select position_id from assignations where active = 1)']                
            end
        end
        
        
end


